

package com.hazelcast.jet.impl.connector;

import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.function.FunctionEx;
import com.hazelcast.internal.serialization.SerializationService;
import com.hazelcast.jet.core.Processor;
import com.hazelcast.security.PermissionsUtil;

import javax.annotation.Nonnull;
import java.io.Serial;

/**
 * A ProcessorSupplier that checks permission of processor function
 */
class ProcessorFunctionConnectorSupplier extends AbstractHazelcastConnectorSupplier {

    @Serial
    private static final long serialVersionUID = 1L;

    private final FunctionEx<HazelcastInstance, Processor> processorFunction;

    ProcessorFunctionConnectorSupplier(String dataConnectionName, String clientXml, FunctionEx<HazelcastInstance, Processor> processorFunction) {
        super(dataConnectionName, clientXml);
        this.processorFunction = processorFunction;
    }

    @Override
    public void init(@Nonnull Context context) {
        PermissionsUtil.checkPermission(processorFunction, context);
        super.init(context);
    }

    @Override
    protected Processor createProcessor(HazelcastInstance instance, SerializationService serializationService) {
        return processorFunction.apply(instance);
    }
}
